//
//  WYBindlingWeChatController.m
//  Boss
//
//  Created by admin on 2018/6/26.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYBindlingWeChatController.h"
#import "WXApi.h"
#import "WYDoneMessageController.h"
@interface WYBindlingWeChatController ()

@end

@implementation WYBindlingWeChatController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WXLogin:) name:@"WXAuthorizationSuccess" object:nil];

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WXLoginError:) name:@"WXAuthorizationError" object:nil];
    
    self.view.backgroundColor = [UIColor whiteColor];
//    UIBarButtonItem *item  = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"comment_close-icon"] style:(UIBarButtonItemStylePlain) target:self action:@selector(exitAction:)];
//    UIButton *btn = [[UIButton alloc]init];
//    btn.frame = CGRectMake(-10, 0, 44, 44);
//    [btn setImage:[UIImage imageNamed:@"comment_close-icon"] forState:UIControlStateNormal];
//    [btn addTarget:self action:@selector(exitAction:) forControlEvents:(UIControlEventTouchUpInside)];
//    
//     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
//    
//     [self wr_setNavBarBackgroundAlpha:0];
}
-(void)exitAction:(UIButton *)item
{
    
}
- (IBAction)exit:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}



-(void)WXLogin:(NSNotification *)notification
{
    WEAKSELF
    [WYHttpServer bindingWechatWithPhone:self.phone WithCode:notification.object[@"code"] SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        
        if(success){
            NSString *token = [WYStoreModule currentTempToken];
            [WYStoreModule storeToken:token];
            
            NSString *userid = [WYStoreModule currentTempUserId:@""];
            [WYStoreModule storeUserId:userid];
            
            WYDoneMessageController *dvc = [[WYDoneMessageController alloc]init];
            [self.navigationController pushViewController:dvc animated:YES];
            [self sendShare];
        }else{
            [weakSelf toast:errorMessage];
           //[weakSelf.navigationController popViewControllerAnimated:YES];
        }
    }];
    
}
-(void)sendShare
{
    
    [WYHttpServer getShareRedPacketSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            
        }
    }];
}



-(void)WXLoginError:(NSNotification *)notification
{
    
    
    
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)bindWechatAction:(id)sender {
    
    if([WXApi isWXAppInstalled]){
        SendAuthReq *request = [[SendAuthReq alloc]init];
        request.state = @"com.boss.redpacket";
        request.scope = @"snsapi_userinfo";
        [WXApi sendReq:request];
    }
    
    
    
}

@end
